/**
 * Copyright (c) 2006-2012 Las Venturas Playground, LVP Mineground
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package mineground.util;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Providing a single and centralized class for logging information to various sources, depending
 * on the information being logged, is convenient for when we want to adjust the destinations,
 * format or frequency at which information will be stored.
 *
 * The Log class provides three methods static methods aiding in this goal, each meant for a
 * certain severity of the information that should be logged.
 * 
 * notice() should be used for informational messages with no importance.
 * warning() should be used for more pressing issues, such as recoverable issues.
 * error() should be used for serious faults or canceled operations.
 */
public class Log {
    /**
     * Declare a Java Logger instance which will be used to send messages to.
     */
    private static Logger mLogger = Logger.getLogger("Mineground");
    
    /**
     * Output a notice. Notices are mostly informational messages which have no severity or priority
     * in the system, thus are safe to ignore. Status update, limited debugging and really minor,
     * recoverable issues are part of this.
     */
    public static void notice(String format, Object... formatters) {
        mLogger.log(Level.INFO, String.format(format, formatters));
    }
    
    /**
     * Warnings are more severe messages which should, in normal runtime, occur very rarely to not
     * ever at all. Generally they should indicate issues which the system can recover from (for
     * example, a player spending more money than they have), but may indicate failure elsewhere.
     * 
     * @todo Consider storing warnings in the database as well.
     */
    public static void warning(String format, Object... formatters) {
        mLogger.log(Level.WARNING, String.format(format, formatters));
    }
    
    /**
     * Errors should not occur. They indicate more severe issues which can be as bad as entire
     * canceled procedures because of input errors. They should appear in code-paths which must
     * not be executed in normal run-time, so their presence in log-files should be rare.
     * 
     * @todo Errors should be stored in the database as well.
     */
    public static void error(String format, Object... formatters) {
        mLogger.log(Level.SEVERE, String.format(format, formatters));
    }
}
